<template>
  <div>
    <van-field v-model="nickname" label="名字" placeholder="名字" />
    <van-field v-model="mobile" label="手机号" placeholder="手机号" />
    <van-field
      v-model="password"
      type="password"
      label="密码"
      placeholder="请输入密码"
    />
    <van-field v-model="address" label="地址" placeholder="地址" />
    <van-field v-model="code" label="验证码" placeholder="验证码" /><van-button
      type="primary"
      @click="submit"
      >获取验证码</van-button
    >
    <br /><br />

    <van-button type="primary" @click="register">注册</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      nickname: "",
      mobile: "",
      password: "",
      address: "",
      code: "",
    };
  },
  methods: {
    submit: function () {
      if (this.nickname == "") {
        this.$toast.fail("店名不能为空");
        return false;
      }
      if (this.password == "") {
        this.$toast.fail("密码不能为空");
        return false;
      }
      if (this.mobile == "") {
        this.$toast.fail("手机号不能为空");
        return false;
      }
      if (this.address == "") {
        this.$toast.fail("地址不能为空");
        return false;
      }
      this.myaxios(this.host + "users/smscode/", "post", {
        mobile: this.mobile,
      }).then((data) => {
        console.log(data);
        if (data.errcode == 0) {
          this.$toast.success(data.msg);
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    register: function () {
      this.myaxios(this.host + "shops/register/", "post", {
        nickname: this.nickname,
        mobile: this.mobile,
        password: this.password,
        address: this.address,
        sms_code: this.code,
      }).then((data) => {
        console.log(data);
        if (data.errcode == 0) {
          this.$toast.success(data.msg);
          this.$router.push("/");
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
};
</script>

<style>
</style>